package fr.inserm.u915.tabixserver;

import java.util.Set;

public class Group
	{
	private String id;
	private Set<String> userIds=null;
	private final static Group ALL=new Group("*")
		{
		public boolean containsUserId(String id)
			{
			return true;
			}
		public String toString()
			{
			return "public";
			};
		};
	Group(String id)
		{
		this.id=id;
		}
	
	void setUserIds(Set<String> userIds) {
		this.userIds = userIds;
		}
	
	public static Group getDefaultGroup()
		{
		return Group.ALL;
		}
	
	public String getId()
		{
		return id;
		}
	
	public boolean containsUserId(String id)
		{
		return userIds!=null && userIds.contains(id);
		}

	@Override
	public int hashCode()
		{
		final int prime = 31;
		int result = 1;
		result = prime * result +  id.hashCode();
		return result;
		}

	@Override
	public boolean equals(Object obj)
		{
		if (this == obj) { return true; }
		if (obj == null) { return false; }
		if (getClass() != obj.getClass()) { return false; }
		Group other = (Group) obj;
		return id.equals(other.id);
		}
	
	@Override
	public String toString()
		{
		return id;
		}
	}
